// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.

#ifndef HOST_STATE_OBSERVER_H_
#define HOST_STATE_OBSERVER_H_

#include "status/rot_status.h"
#include "host_state_manager.h"


/**
 * Observer interface for handling host state events.
 */
struct host_state_observer {
	/**
	 * Notification that the active PFM region has changed.
	 *
	 * Arguments passed with the notification will never be null.
	 *
	 * @param observer The observer instance being notified.
	 * @param manager The manager generating the event.
	 */
	void (*on_active_pfm) (struct host_state_observer *observer,
		struct host_state_manager *manager);

	/**
	 * Notification that the read only flash device has changed.
	 *
	 * Arguments passed with the notification will never be null.
	 *
	 * @param observer The observer instance being notified.
	 * @param manager The manager generating the event.
	 */
	void (*on_read_only_flash) (struct host_state_observer *observer,
		struct host_state_manager *manager);

	/**
	 * Notification that the dirty state of flash has changed.
	 *
	 * Arguments passed with the notification will never be null.
	 *
	 * @param observer The observer instance being notified.
	 * @param manager The manager generating the event.
	 */
	void (*on_inactive_dirty) (struct host_state_observer *observer,
		struct host_state_manager *manager);

	/**
	 * Notification that the active recovery image has changed.
	 *
	 * Arguments passed with the notification will never be null.
	 *
	 * @param observer The observer instance being notified.
	 * @param manager The manager generating the event.
	 */
	void (*on_active_recovery_image) (struct host_state_observer *observer,
		struct host_state_manager *manager);

	/**
	 * Notification that the dirty state of a PFM has changed.
	 *
	 * Arguments passed with the notification will never be null.
	 *
	 * @param observer The observer instance being notified.
	 * @param manager The manager generating the event.
	 */
	void (*on_pfm_dirty) (struct host_state_observer *observer,
		struct host_state_manager *manager);

	/**
	 * Notification that the run-time validation status has changed.
	 *
	 * Arguments passed with the notification will never be null.
	 *
	 * @param observer The observer instance being notified.
	 * @param manager The manager generating the event.
	 */
	void (*on_run_time_validation) (struct host_state_observer *observer,
		struct host_state_manager *manager);

	/**
	 * Notification that the bypass mode state has changed.
	 *
	 * Arguments passed with the notification will never be null.
	 *
	 * @param observer The observer instance being notified.v
	 */
	void (*on_bypass_mode) (struct host_state_observer *observer,
		struct host_state_manager *manager);

	/**
	 * Notification that the unsupported flash state has changed.
	 *
	 * Arguments passed with the notification will never be null.
	 *
	 * @param observer The observer instance being notified.
	 * @param manager The manager generating the event.
	 */
	void (*on_unsupported_flash) (struct host_state_observer *observer,
		struct host_state_manager *manager);
};


#define	HOST_STATE_OBSERVER_ERROR(code)		ROT_ERROR (ROT_MODULE_HOST_STATE_OBSERVER, code)

/**
 * Error codes that can be generated by a host processor observer.
 */
enum {
	HOST_STATE_OBSERVER_INVALID_ARGUMENT = HOST_STATE_OBSERVER_ERROR (0x00),	/**< Input parameter is null or not valid. */
	HOST_STATE_OBSERVER_NO_MEMORY = HOST_STATE_OBSERVER_ERROR (0x01),			/**< Memory allocation failed. */
};


#endif /* HOST_STATE_OBSERVER_H_ */
